from django.db import models

# Create your models here.
class Products(models.Model):

    IMAGE_DOWNLOAD_STATUS = (
        (1, "采集完成"),
        (2, "")
    )
    # goods = models.ForeignKey(Goods, on_delete=models.CASCADE, verbose_name='商品')
    # category = models.ForeignKey(GoodsCategory, on_delete=models.PROTECT, verbose_name='从属类别')
    brand = models.CharField(max_length=64, verbose_name="Brand")
    product_name = models.CharField(max_length=256, verbose_name="产品名称")
    myasin = models.CharField(max_length=16, null=False, unique=True, verbose_name='原始ASIN')
    category = models.CharField(max_length=128, default='', verbose_name='分类')
    price = models.DecimalField(max_digits=10, default=None, decimal_places=2, verbose_name='价格')
    buy_box_price = models.DecimalField(max_digits=10, null=True, decimal_places=2, verbose_name='BuyBox价格')
    offer_min_price = models.DecimalField(max_digits=10, null=True, decimal_places=2, verbose_name='offer最低价')
    offer = models.IntegerField(default=0, verbose_name='供应商')
    comments = models.IntegerField(default=0, verbose_name='评价数')
    goods_version = models.CharField(max_length=64, verbose_name="型号")
    status = models.SmallIntegerField(choices=IMAGE_DOWNLOAD_STATUS, default=2, verbose_name='图片是否采集完成')
    color = models.CharField(max_length=64, verbose_name='颜色')
    size = models.CharField(max_length=64, verbose_name='尺码')
    country = models.CharField(max_length=256, verbose_name='国家')
    star = models.CharField(max_length=8, default='', verbose_name='评分')
    seller_type = models.CharField(max_length=64, default='', verbose_name='卖家类型')
    haven_cart = models.BooleanField(default='False', verbose_name='有无购物车')
    # stock = models.IntegerField(default=0, verbose_name='库存')
    # sales = models.IntegerField(default=0, verbose_name='销量')
    # is_launched = models.BooleanField(default=True, verbose_name='是否上架销售')
    product_url = models.CharField(max_length=256, default='', null=True, blank=True, verbose_name='产品地址')
    small_image_url = models.CharField(max_length=512, default='', null=True, blank=True, verbose_name='缩略图地址')
    heavy_image_url = models.CharField(max_length=1024, default='', null=True, blank=True, verbose_name='高清图地址')
    local_image_url = models.CharField(max_length=128, default='', null=True, blank=True, verbose_name='本地图地址')
    remark = models.CharField(max_length=128, default='', verbose_name='备注')
    goods_short_desc = models.CharField(max_length=512, default='', verbose_name='产品短描述')
    goods_long_desc = models.CharField(max_length=512, default='', verbose_name='产品长描述')
    task = models.CharField(max_length=64, verbose_name='任务')
    get_time = models.CharField(max_length=32, default='', verbose_name='Date First Available3')
    best_seller_rank = models.CharField(max_length=32, default='', verbose_name="Best Sellers Rank")
    can_sell_info = models.CharField(max_length=128, default='', verbose_name='可售信息')
    general_info = models.CharField(max_length=128, default='', verbose_name='通用信息')
    parent = models.ForeignKey(to='self', null=True, on_delete=models.CASCADE, verbose_name='父id')
    user = models.CharField(max_length=64, default='', verbose_name='上传人')
    # store = models.CharField(max_length=64, default='', verbose_name='上传店铺')


    class Meta:
        db_table = 'tb_products'
        verbose_name = '产品'
        verbose_name_plural = verbose_name

    def __str__(self):
        return '%s: %s' % (self.id, self.brand)


class AsinCompare(models.Model):
    old_asin = models.ForeignKey(Products, to_field='myasin', null=False, verbose_name='旧ASIN')
    new_asin = models.CharField(max_length=16, default='', verbose_name='新ASIN')
    user = models.CharField(max_length=64, default='', verbose_name='上传人')
    store = models.CharField(max_length=64, default='', verbose_name='关联店铺')

    class Meta:
        db_table = 'tb_asin_compare'
        verbose_name = '产品'
        verbose_name_plural = verbose_name
